var tooltip = function () {
    var id = 'tooltip';
    var top = 3;
    var left = 3;
    var maxw = 300;
    var speed = 10;
    var timer = 20;
    var endalpha = 95;
    var alpha = 0;
    var toolTip, toolTipTop, toolTipContent, toolTipBottom, toolTipHeight;
    var ie = document.all ? true : false;
    return {
        show: function (valueToDisplay, width) {
            if (toolTip == null) {
                toolTip = document.createElement('div');
                toolTip.setAttribute('id', id);
                toolTipTop = document.createElement('div');
                toolTipTop.setAttribute('id', id + 'top');
                toolTipContent = document.createElement('div');
                toolTipContent.setAttribute('id', id + 'cont');
                toolTipBottom = document.createElement('div');
                toolTipBottom.setAttribute('id', id + 'bottom');
                toolTip.appendChild(toolTipTop);
                toolTip.appendChild(toolTipContent);
                toolTip.appendChild(toolTipBottom);
                document.body.appendChild(toolTip);
                toolTip.style.opacity = 0;
                toolTip.style.filter = 'alpha(opacity=0)';
                document.onmousemove = this.pos;
            }
            toolTip.style.display = 'block';
            toolTipContent.innerHTML = valueToDisplay;
            toolTip.style.width = width ? width + 'px' : 'auto';
            if (!width && ie) {
                t.style.display = 'none';
                b.style.display = 'none';
                toolTip.style.width = toolTip.offsetWidth;
                t.style.display = 'block';
                b.style.display = 'block';
            }
            if (toolTip.offsetWidth > maxw) { toolTip.style.width = maxw + 'px' }
            toolTipHeight = parseInt(toolTip.offsetHeight) + top;
            clearInterval(toolTip.timer);
            toolTip.timer = setInterval(function () { tooltip.fade(1) }, timer);
        },
        pos: function (e) {
            var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
            var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
            toolTip.style.top = (u - toolTipHeight) + 'px';
            toolTip.style.left = (l + left) + 'px';
        },
        fade: function (d) {
            var a = alpha;
            if ((a != endalpha && d == 1) || (a != 0 && d == -1)) {
                var i = speed;
                if (endalpha - a < speed && d == 1) {
                    i = endalpha - a;
                } else if (alpha < speed && d == -1) {
                    i = a;
                }
                alpha = a + (i * d);
                toolTip.style.opacity = alpha * .01;
                toolTip.style.filter = 'alpha(opacity=' + alpha + ')';
            } else {
                clearInterval(toolTip.timer);
                if (d == -1) { toolTip.style.display = 'none' }
            }
        },
        hide: function () {
            clearInterval(toolTip.timer);
            toolTip.timer = setInterval(function () { tooltip.fade(-1) }, timer);
        }
    };
} ();